'''
Created on 2010-6-16

@author: sky
'''
import sys
import gtk.gdk
try:
    import pygtk
    pygtk.require("2.0")
except:
    print 'Version Error'
try:
    import gtk.glade
except:
    sys.exit(1)
if gtk.pygtk_version<(2, 10, 0):
    print "pygtk Required >2.10.0 "
    
    
class GUI:
    def __init__(self):
        self.wn_draw=wn_draw()
        self.base=Base(self)
        self.base.window.show()

class wn_draw:
    def __init__(self):
        self.gladefile=sys.path[0]+"/wiindow.glade"
        print self.gladefile
        self.Wtree=gtk.glade.XML(self.gladefile)
        
        
        self.wnd=self.Wtree.get_widget("wn_draw")
        self.btn_back=self.Wtree.get_widget("btn_back")
        self.label=self.Wtree.get_widget("label")
        self.draw_area=self.Wtree.get_widget("drawingarea")
        
        self.draw_area.set_size_request(400,200)
        self.draw_area.show()
        self.dic={
                 "on_btn_back_clicked":self.on_btn_back_clicked
                 }
        self.Wtree.signal_autoconnect(self.dic)
        
    def on_btn_back_clicked(self,widget):
        x,y,height,width=widget.get_allocation()
        print x,y,height,width
        window=self.draw_area.window
        self.gc=gtk.gdk.GC(window)
        self.pixmap=gtk.gdk.Pixmap(widget.window, width, height)
        #self.pixmap.draw_rectangle(widget.get_style.white_gc,True,0,0,width,height)
        window.draw_point(self.gc,5,5)
        window.draw_rectangle(self.gc,True,0,0,50,50)
        #self.draw_able=gtk.gdk.Drawable()
        #self.draw_able.draw_point(self.gc,50,50)
        #self.wnd.hide()
            
        
class Base:
    def __init__(self,pwidget):
        #set glade file
        self.gladefile=sys.path[0]+"/wiindow.glade"
        print self.gladefile
        self.Wtree=gtk.glade.XML(self.gladefile)
        
        self.pwidget=pwidget
        #Get Window and Widget
        self.window=self.Wtree.get_widget("window")
        self.button=self.Wtree.get_widget("button_click")
        self.label=self.Wtree.get_widget("label_status")
        self.menubar=self.Wtree.get_widget("menubar1")
        self.menuitem1=self.Wtree.get_widget("menuitem1")
        self.menuitem2=self.Wtree.get_widget("menuitem2")
        self.menuitem3=self.Wtree.get_widget("menuitem3")
        self.menuitem4=self.Wtree.get_widget("menuitem4")
        self.img_mt_start=self.Wtree.get_widget("img_mt_start")
        self.img_mt_score=self.Wtree.get_widget("img_mt_score")
        self.img_mt_quit=self.Wtree.get_widget("img_mt_quit")
        self.img_start=self.Wtree.get_widget("img_start")
        self.drawar=self.Wtree.get_widget("drawar")
        self.drawar.hide()
        self.drawable=self.drawar.window
        print self.drawable
        #set signal
        self.dic={
                  "on_window_delete_event":gtk.main_quit,
                  "on_window_destory":gtk.main_quit,
                  "on_button_click_clicked":self.on_button_click_clicked,
                  "on_menuitem1_select":self.on_menuitem1_select,
                  "on_menuitem2_select":self.on_menuitem2_select,
                  "on_menuitem3_select":self.on_menuitem3_select,
                  "on_menuitem4_select":self.on_menuitem4_select,
                  "on_img_mt_start_select":self.on_img_mt_start_select,
                  "on_img_mt_start_activate":self.on_img_mt_start_activate,
                  "on_img_mt_score_activate":self.on_img_mt_score_activate,
                  "on_img_mt_quit_activate":self.on_img_mt_quit_activate
                  }
        self.lists=['test.jpg','1.jpg','2.gif','3.gif']
        self.i=0
        self.Wtree.signal_autoconnect(self.dic)
        self.window.show()
    def on_window_delete_event(self,widget,data=None):
        gtk.main_quit()
    def on_button_click_clicked(self,widget):
        #self.gc=gtk.Style.fg_gc[GTK_WIDGET_STATE(widget)]
        self.gc =gtk.Style.fg
        #self.drawable.draw_line(self.gc,0,0,50,50)
        print self.i
        self.i=self.i+1
        if self.i%2==0:
            self.label.set_text("Click To Show Img")
            self.img_start.hide()
            self.pwidget.wn_draw.wnd.show()
        if self.i%2==1:
            self.label.set_text("Click To Hide Img")
            self.img_start.show()
            self.pwidget.wn_draw.wnd.hide()
        
        
    def on_menuitem1_select(self,widget):
        self.label.set_text("View")
    def on_menuitem2_select(self,widget):
        self.label.set_text("Edit")
    def on_menuitem3_select(self,widget):
        self.label.set_text("View")
    def on_menuitem4_select(self,widget):
        self.label.set_text("Help")
    def on_img_mt_start_select(self,widget):
        self.label.set_text("Start")
    def on_img_mt_start_activate(self,widget):
        self.label.set_text("Start Now")
    def on_img_mt_score_activate(self,widget):
        self.i=self.i+1
        self.label.set_text("Score")
    def on_img_mt_quit_activate(self,widget):
        self.label.set_text("Quit")
        gtk.main_quit()
    def __main__(self):
        self.window.show()
if __name__=="__main__":
    gui=GUI()
    gtk.main()
        
